package com.mingxi.backend.service.impl;

import com.mingxi.backend.common.Result;
import com.mingxi.backend.pojo.dto.Token;
import com.mingxi.backend.mapper.UserMapper;
import com.mingxi.backend.pojo.dto.LoginDTO;
import com.mingxi.backend.pojo.entity.User;
import com.mingxi.backend.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;


    @Override
    public Result login(LoginDTO loginDTO) {
        User user = userMapper.getUserInfoByName(loginDTO.getUsername());
        if(user == null){
            return Result.error("密码错误");
        }
        if(loginDTO.getPassword().equals(user.getPassword())) {
            return Result.success(new Token("token-admin"), "登录成功");
        }else{
            return Result.error("密码错误");
        }
    }
}
